package com.springboot.news.controller;

import com.springboot.news.domain.dto.StoreDto;
import com.springboot.news.domain.po.PageBean;
import com.springboot.news.domain.po.Result;
import com.springboot.news.domain.query.StoreQuery;
import com.springboot.news.domain.vo.PageableVO;
import com.springboot.news.domain.vo.StoreVo;
import com.springboot.news.service.StoreService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/store")
public class StoreController {
    @Resource
    private StoreService storeService;

    @PostMapping("/storeList")
    public Result<PageableVO<StoreVo>> storeList (@RequestBody StoreQuery dto) {
        return Result.success(storeService.storeList(dto));
    }
    @PostMapping("/create")
    public Result<String> create(@RequestBody StoreDto dto) {
        storeService.create(dto);
        return Result.success("添加成功");
    }
    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam Integer id) {
        storeService.delete(id);
        return Result.success("删除成功");
    }
    @PostMapping("/update")
    public Result<String> update(@RequestBody @Validated(StoreDto.Update.class) StoreDto dto) {
        storeService.update(dto);
        return Result.success("编辑成功");
    }
    @GetMapping("/detail")
    public Result<StoreVo> detail(@RequestParam Integer id) {
        StoreVo vo = storeService.detail(id);
        return Result.success(vo);
    }
}
